<include file="Index/_meta" />
<body>
<div class="layui-fluid" style="margin-top: 20px">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">上级权限</label>
            <div class="layui-input-block">
                <select name="parent_id" size="1">
                    <option value="0">顶级权限</option>
                    <?php foreach($pridata as $v){?>
                    <option value="<?php echo $v['id']?>">
                        <?php echo str_repeat('-',8*$v['level']),$v
['pri_name']?>
                    </option>
                    <?php }?>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限名称:</label>
            <div class="layui-input-block">
                <input type="text" name="pri_name" lay-verify='pri_name' autocomplete="off" placeholder="请输入权限名称" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">模块名称:</label>
            <div class="layui-input-block">
                <input type="text" name="module_name" lay-verify='module_name' placeholder="请输入模块名称" autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">控制器名称:</label>
            <div class="layui-input-block">
                <input type="text" name="controller_name" lay-verify='controller_name' placeholder="请输入控制器名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">方法名称:</label>
            <div class="layui-input-block">
                <input type="text" name="action_name" lay-verify='action_name' placeholder="请输入方法名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" lay-submit="" lay-filter="sub" class="layui-btn">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script type="text/javascript" src="__PUBLIC__/frame/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        // 操作对象
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery;
        // 验证
        form.verify({
            pri_name: function (value) {
                if (value == "") {
                    return "请输入权限名称";
                }
            },
            module_name: function (value) {
                if (value == "") {
                    return "请输入模块名称";
                }
            },
            controller_name: function (value) {
                if (value == "") {
                    return "请输入控制器名称";
                }
            },
            action_name: function (value) {
                if (value == "") {
                    return "请输入方法名称";
                }
            }
        });

        // 提交监听
        form.on('submit(sub)', function (data) {
            var data = data.field;
            var url = '/index.php/home/privilege/add'
            $.post(url, data,
                function (result) {
                    if(result.status == '0'){
                        layer.alert(result.message);
                    }
                    if(result.status == '1'){
                        layer.open({
                            content:result.message,
                            icon:1,
                            yes:function(){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.$('.refresh').click();  //添加成功获取一下数据
                                parent.layer.close(index); //再执行关闭
                            }
                        });
                    }
                },
                "JSON");
            return false;
        });
    })
</script>